
import { _decorator, Component, Layers, Node, resources, sp, Sprite, SpriteFrame, UITransform } from 'cc';
import Levels from '../../Levels';
import { TILE_TYPE_ENUM } from '../../Enums';
const { ccclass, property } = _decorator;

export const TILE_WIDTH = 55
export const TILE_HEIGHT = 55

@ccclass('TileManager')
export class TileManager extends Component {
    type: TILE_TYPE_ENUM
    moveable: boolean
    turnable: boolean

    init(type: TILE_TYPE_ENUM, spriteFrame: SpriteFrame, i: number, j: number) {
        this.type = type
        if (this.type.includes('WALL')) {
            this.moveable = false
            this.turnable = false
        } else if ([
            TILE_TYPE_ENUM.CLIFF_CENTER,
            TILE_TYPE_ENUM.CLIFF_LEFT,
            TILE_TYPE_ENUM.CLIFF_RIGHT,
        ].some(v => v === this.type)) {
            this.moveable = false
            this.turnable = true
        } else if (this.type === TILE_TYPE_ENUM.FLOOR) {
            this.moveable = true
            this.turnable = true
        }

        const sprite = this.addComponent(Sprite)
        sprite.spriteFrame = spriteFrame

        const transform = this.getComponent(UITransform)
        transform.setContentSize(TILE_WIDTH, TILE_HEIGHT)

        this.node.setPosition(i * TILE_WIDTH, -j * TILE_HEIGHT)
    }
}
